#include "spell.h"

const QString Spell::KEY_EFFECT = "effect";
const QString Spell::KEY_DURATION = "duration";
const QString Spell::KEY_DIFFICULTY = "difficulty";
const QString Spell::KEY_RANGE = "range";
const QString Spell::KEY_INCANTATION = "incantation";
const QString Spell::KEY_THREADS = "threads";
const QString Spell::KEY_DISCIPLINE = "discipline";
const QString Spell::KEY_CIRCLE = "circle";

Spell::Spell(const QMap<QString, QString> &values)
    : XMLItem(values)
{
    Q_ASSERT(values.contains(KEY_EFFECT));
    Q_ASSERT(values.contains(KEY_DURATION));
    Q_ASSERT(values.contains(KEY_DIFFICULTY));
    Q_ASSERT(values.contains(KEY_RANGE));
    Q_ASSERT(values.contains(KEY_INCANTATION));
    Q_ASSERT(values.contains(KEY_THREADS));
    Q_ASSERT(values.contains(KEY_DISCIPLINE));
    Q_ASSERT(values.contains(KEY_CIRCLE));

    _effect = values[KEY_EFFECT];
    _duration = values[KEY_DURATION];
    _difficulty = values[KEY_DIFFICULTY];
    _range = values[KEY_RANGE];
    _incantation = values[KEY_INCANTATION];
    _threads = values[KEY_THREADS];
    _discipline = values[KEY_DISCIPLINE];
    _circle = values[KEY_CIRCLE].toInt();
}

QString Spell::keyValue(const QString &key) const
{
    if (key == KEY_EFFECT) return effect();
    if (key == KEY_DURATION) return duration();
    if (key == KEY_DIFFICULTY) return difficulty();
    if (key == KEY_RANGE) return range();
    if (key == KEY_INCANTATION) return incantation();
    if (key == KEY_THREADS) return threads();
    if (key == KEY_DISCIPLINE) return discipline();
    if (key == KEY_CIRCLE) return QString::number(circle());

    return XMLItem::keyValue(key);
}
